<?php
echo $this->renderPartial("leftnav", array());
?>
<!-- ================================== 712 Area - Right Side =========================================================== -->
<div class="grid_712">
    <div class="box">
        <h1>Đăng Nhập</h1>

        <form
            id     = "frm_login"
            name   = "frm_login"
            action = "<?=Yii::app()->createUrl("account/login");?>"
            target = "integration_asynchronous"
            method = "post"
            class  = "form_input"
        >
            <fieldset>
                <input
                    id    = "os_query"
                    name  = "os_query"
                    type  = "hidden"
                    value = "account_login"
                />

                <div class="form_input_row">
                    <label class="label_title">Tên Tài Khoản:*</label>

                    <input
                        id         = "txt_account"
                        name       = "txt_account"
                        title      = "Tên Tài khoản Của Bạn"
                        type       = "text"
                        value      = ""
                        class      = "form_textbox textbox_css3"
                        onkeypress = "return keypress_alphanumberic(event);"
                        tabindex   = "1"
                    />

                    <label
                        id    = "lbl_account_validation" 
                        class = "lable_validation"
                    >Bạn phải nhập vào tên tài khoản hơn 4 ký tự.</label>
                </div>

                <div class="form_input_row">
                    <label class="label_title">Mật Khẩu:*</label>

                    <input
                        id       = "txt_password"
                        name     = "txt_password"
                        title    = "Mật Khẩu Của Bạn"
                        type     = "password"
                        value    = ""
                        class    = "form_textbox textbox_css3"
                        tabindex = "2"
                    />

                    <label
                        id    = "lbl_password_validation" 
                        class = "lable_validation"
                    >Bạn phải nhập vào mật khẩu hơn 4 ký tự.</label>
                </div>

                <?php if ( isset(Yii::app()->session["ss_login_fail"]) && Yii::app()->session["ss_login_fail"] >= 3) {?>
                <div class="form_input_row">
                    <label class="label_title">Mã Xác Nhận:*</label>

                    <div class="input_items_horizon" style="padding-top: 0px;">
                        <input
                            id       = "txt_catcha"
                            name     = "txt_catcha"
                            value    = ""
                            class    = "item_text textbox_css3"
                            style    = "width: 152px;"
                            onblur   = "validation_onblur(this,'lbl_catcha_validation')"
                            tabindex = "3"
                        />

                        <img
                            src    = "<?=Yii::app()->baseUrl;?>/assets/tool/security_image/securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"
                            id     = "image"
                            align  = "top"
                            height = "24px"
                        />

                        <a
                            href  = "<?=Yii::app()->baseUrl;?>/assets/tool/security_image/securimage_play.php"
                            style = "font-size: 13px"
                        >
                            <img
                                alt = "Reload Image"
                                src = "<?=Yii::app()->baseUrl;?>/assets/tool/security_image/images/audio_icon.gif"
                            />
                        </a>

                        <a
                            href    = "javascript:void(0);"
                            onclick = "document.getElementById('image').src = '<?=Yii::app()->baseUrl;?>/assets/tool/security_image/securimage_show.php?sid=' + Math.random();"
                        >
                            <img
                                alt = "Reload Image"
                                src = "<?=Yii::app()->baseUrl;?>/assets/tool/security_image/images/refresh.gif"
                            />
                        </a>
                    </div>

                    <label
                        id    = "lbl_catcha_validation"
                        class = "lable_validation"
                    >Bạn chưa nhập mã xác nhận.</label>
                </div>
                <?php }?>

                <div class="form_input_row" style="border: none;">
                    <div class="input_items_horizon">
                        <input
                            title    = "gửi yêu cầu"
                            name     = "btn_login"
                            id       = "btn_login"
                            type     = "submit"
                            value    = "Đăng Nhập"
                            class    = "input_button button_css3"
                            tabindex = "4"
                        />
                    </div>
                </div>
            </fieldset>
        </form>
    </div><!-- End box -->
</div><!-- End grid_712 -->
<!-- ================================ End 712 Area - Right Side ========================================================= -->

<script type="text/javascript">
$(document).ready(function() {
    $('#txt_account').focus();

    //attach a submit handler to the form
    $("#frm_login").submit(function(event) {
        
        //stop form from submitting normally
        event.preventDefault();
        
        var bool_submit = form_onsubmit("frm_login");
        if (bool_submit == true) {

            // get some values from elements on the page: 
            var $form         = $( this ),
            txt_account        = $form.find( 'input[name="txt_account"]' ).val(),
            txt_password    = $("#txt_password").val(),
            txt_catcha        = "",
            os_query        = $("#os_query").val(),
            url                = $form.attr("action");
    
            if(document.getElementById("txt_catcha") != null){
                txt_catcha = $("#txt_catcha").val();
            }
    
            $.post( url,{
                os_query        : os_query,
                txt_account        : txt_account,
                txt_password    : txt_password,
                txt_catcha        : txt_catcha
            },function( string ) {
                var arr_result = $.parseJSON(string);

                if(arr_result.error != null){
                    alert(arr_result.error);
                    document.getElementById('image').src = "<?=Yii::app()->baseUrl;?>/assets/tool/security_image/securimage_show.php?sid=" + Math.random();
                    return;
                }

                //alert (arr_result.count);return;
                var i_count = arr_result.count;
                if(i_count > 0 && i_count<3)
                    alert("Mật khẩu của bạn không đúng.");
                else if (i_count == 3)
                    load_page("<?=Yii::app()->createUrl("account/index");?>");
                else if (i_count > 3) {
                    alert("Mật khẩu của bạn không đúng.");
                    document.getElementById('image').src = "<?=Yii::app()->baseUrl;?>/assets/tool/security_image/securimage_show.php?sid=" + Math.random();
                }
                else if (i_count == 0)
                    load_page("<?=Yii::app()->homeUrl;?>");
            });

        }//end if (bool_submit == true) {
        
    });

    function form_onsubmit(param)
    {
        if (document.forms[param].txt_account.value=="" || document.forms[param].txt_account.value.length < 4){
            $("#lbl_account_validation").fadeIn("slow", "linear");
            $("#txt_account").focus();
            return false;
        }

        if (document.forms[param].txt_password.value=="" || document.forms[param].txt_password.value.length < 4){
            $("#lbl_password_validation").fadeIn("slow", "linear");
            $("#txt_password").focus();
            return false;
        }

        if(document.forms[param].txt_catcha != null && document.forms[param].txt_catcha.value == ""){
            $("#lbl_catcha_validation").fadeIn("slow", "linear");
            $("#txt_catcha").focus();
            return false;
        }
        
        return true;
    }

    $('#txt_account').change(function() {
        var name_without_space = $("#txt_account").val().replace(/ /g,'');
        var name_without_special_char = name_without_space.replace(/[<>']+/g,'');
        $(this).attr("value", name_without_special_char );
    });
    
});
</script>